package com.foreknow.oop;

/**
 * @author shkstart
 * @create 2021-07-23 10:23
 */
public class ObjectArray {
    public  Student[] getAllMessage(Student stuarray[]){
        //4.遍历数组获取到数组中的Student对象信息
        for (int i = 0; i < stuarray.length; i++) {
            Student s=stuarray[i];
            System.out.println(s.getName()+"*******"+s.getAge());
        }
        System.out.println("------------------");

        // foreach ：号后填数组的名称   ：号前填数组的类型 + 起的名
        for (Student ss:stuarray) {
            System.out.println(ss.getName() + "*******" + ss.getAge());
        }
        return  stuarray;

    }
    public Student[] getAll(){
        Student array[]=new Student[2];
        //2创建两个学生对象
        Student s1=new Student();
        s1.setName("tom");
        s1.setAge(20);
        Student s2=new Student();
        s2.setName("fender");
        s2.setAge(30);
        array[0]=s1;
        array[1]=s2;
        return array;
    }
    public static void main(String[] args) {
        ObjectArray objectArray=new ObjectArray();
        //1创建一个Student的数组容器
       Student array[]=objectArray.getAll();
       objectArray.getAllMessage(array);
    }
}
